﻿
using DA.Core.Mes;
using DA.Core.Plcs;
using DA.DataBase.DataBaseContext;
using DA.Utility.Extensions;

namespace DA.Core.WorkFlows
{
    public class BaseWorkFlow : IWorkFlow
    {
        public string FlowName { get; set; }
        //protected BaseContext dbContext;
        public BaseWorkFlow()
        {
            //this.dbContext = dbContext as BaseContext;
        }

        public virtual void DoWorkFlow(IBasePlc plc, IClient client, Model.Configure.Station station)
        {
        }
        public Task<object> ReadPlcVar(IBasePlc plc, Model.Configure.Station station,string addressName)
        {
            var variable = station.PlcAddresses.FirstOrDefault(p => p.Name == addressName);
            var address = variable.Address;
            var dataType = variable.DataType.ToDaType();
            return plc.ReadAsync(address, dataType);
        }
        public Task<bool> WritePlcVar(IBasePlc plc, Model.Configure.Station station,string addressName, object value)
        {
            var variable = station.PlcAddresses.FirstOrDefault(p => p.Name == addressName);
            var address = variable.Address;
            var dataType = variable.DataType.ToDaType();
            return plc.WriteAsync(address, dataType, value);
        }
    }
}
